
package com.ctrip.corp.obt.shard.sql.mybatis.interceptor.dialect;


import com.ctrip.corp.obt.generic.utils.ExceptionUtils;

/**
 * Postgre 数据库分页语句组装实现
 *
 * @author marco.zheng
 * @since 2022-03-15
 */
public class PostgreDialect implements IDialect {

    @Override
    public PageDialectModel buildPaginationSql(String originalSql, long offset, long limit) {
        StringBuilder sql = new StringBuilder(originalSql).append(" LIMIT ").append(FIRST_MARK);
        if (offset != 0L) {
            sql.append(" OFFSET ").append(SECOND_MARK);
            return new PageDialectModel(sql.toString(), limit, offset).setConsumerChain();
        } else {
            return new PageDialectModel(sql.toString(), limit).setConsumer(true);
        }
    }

    @Override
    public String buildTableSearchSql(String tableName) {
        throw ExceptionUtils.mpe("Do not support now");
    }
}
